#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<malloc.h>
int main()
{
	struct stat st;
	int n = stat("test.txt",&st);
	if(n<0)
		return 1;
	printf("file size:%lu\n",st.st_size);
	int fd = open("test.txt",O_RDONLY);
	if(fd<0)
	{
		perror("open");
		return 2;
	}
	printf("fd:%d\n",fd);
	char* buffer = (char*)malloc(st.st_size + 1);
	n = read(fd,buffer,st.st_size);
	if(n>0)
	{
		buffer[n] = '\0';
		printf("%s",buffer);
	}
	free(buffer);
	close(fd);
	return 0;
}
